/*
 * Powered By [pkuWx]
 * Web Site: http://www.wuxi.ss.pku.edu.cn
 * Since 2015 - 2015
 */

package cn.edu.pku.wxlib.adminuser.dao;

import java.util.*;

import cn.edu.pku.wxlib.adminuser.model.*;
import cn.edu.pku.wxlib.adminuser.service.*;
import cn.edu.pku.wxlib.adminuser.vo.query.*;
import javacommon.base.*;
import javacommon.util.*;
import javacommon.page.Page;

/**
 * @version 1.0
 * @since 1.0
 */








import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;


@Repository
public class AdminuserDao extends BaseIbatis3Dao<Adminuser,AdminuserQuery,java.lang.Integer>{
	
	@Override
	public String getIbatisMapperNamesapce() {
		return "Adminuser";
	}
	
	public void saveOrUpdate(Adminuser entity) {
		if(entity.getAdminId() == null) 
			save(entity);
		else 
			update(entity);
	}
	
	public Page findPage(AdminuserQuery query) {
		return pageQuery("Adminuser.findPage",query);
	}
	
	public List<Adminuser> findById(java.lang.Integer id){
		return getSqlSessionTemplate().selectList("Adminuser.getById", id);
	}	//改变用户状态
	public void changeState(final Object... params) {
		getSqlSessionTemplate().update("Adminuser.changeState", map(params));
	}
	
	protected Map<?, ?> map(final Object... datas) {
		Assert.isTrue(datas.length%2==0, "参数必须为偶数个");
		final Map<Object, Object> map = new HashMap<Object, Object>();
		for (int i = 0; i < datas.length; i += 2) {
			map.put(datas[i], datas[i+1]);
		}
		return map;
	}
	//判断用户是否已存在
	public int checkExist(final Object... params) {
		final Number count = (Number) getSqlSessionTemplate().selectOne("Adminuser.findPage.count", map(params));
		return count.intValue();
	}
}



